package com.yusys.jin.blog.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.beans.factory.annotation.Autowired;

import com.yusys.jin.blog.entity.MailCode;
import com.yusys.jin.blog.mapper.MailCodeMapper;

@WebListener
public class SessionListener implements HttpSessionListener {
    @Autowired
    MailCodeMapper mapper;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        // TODO Auto-generated method stub
        HttpSession session = se.getSession();
        session.setMaxInactiveInterval(30);
        System.err.println(session.getId() + ":创建了");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        String sessionid = session.getId();
        MailCode code = mapper.findSessionByid(sessionid);
        if (code != null) {
            mapper.delete(sessionid);
        }

    }

}
